package com.personal.kousuan.generator.questionlist;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.personal.kousuan.domain.Question;
import com.personal.kousuan.factory.KouSuanGeneratorFactory;
import com.personal.kousuan.factory.KouSuanQuestionsGeneratorFactory;
import com.personal.kousuan.generator.KouSuanGenerator;

public class GeneralKouSuanQuestionGenerator implements
		KouSuanQuestionsGenerator {

	@Override
	public List<Question> generateKouSuanQuestions(int count,String key) {
		String[] kousuanGeneraterKeys = KouSuanQuestionsGeneratorFactory.getInstance().getKouSuanGenerator(key);
		int size = kousuanGeneraterKeys.length;
		Random random = new Random();
		List<Question> questionList = new ArrayList<Question>();
		for(int i = 0;i<count;i++){
			int j = random.nextInt(size);
			String generatorKey = kousuanGeneraterKeys[j];
			KouSuanGenerator generator = KouSuanGeneratorFactory.getInstance().getRandomGenerator(generatorKey);
			questionList.add(generator.generateKouSuanTi());
		}
		return questionList;
	}

}
